#include<stdio.h>
int main()
{
    int a, b;
    while (scanf_s("%d %d", &a, &b) != EOF)
    {
        if (a % 4 == 0 && a % 100 != 0 || a % 400 == 0)
        {
            if (b == 2)
                printf("%d\n", 29);
            else if (b == 4 || b == 9 || b == 11 || b == 6)
                printf("%d\n", 30);
            else
                printf("%d\n", 31);
        }
        else
        {
            if (b == 2)
                printf("%d\n", 28);
            else if (b == 4 || b == 9 || b == 11 || b == 6)
                printf("%d\n", 30);
            else
                printf("%d\n", 31);
        }

    }
    return 0;
}